<?php

namespace App\Jobs;

use Log;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Services\Tool\Order\OrderTool;
use App\Services\Tool\DataBase\SQL;

class CreateOrderPush implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
    protected $goods;
    protected $result;
    protected $input;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($goods, $result, $input)
    {
        $this->goods  = $goods;
        $this->result = $result;
        $this->input  = $input;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::info('-----------进入下单推送-------------');
        $this->result = (array)$this->result;
        $this->result['result'] = (array)$this->result['result'];

        //
        if(isset($this->result['result']) && isset($this->result['result']['order_id'])){
            if(SQL::count(['table' => 'orders',
                           'where' => ['order_id'  => $this->result['result']['order_id'],
                                       'state'     => 1,
                                       'pay_state' => 0,
                                       'is_cancel' => 0]])){

                OrderTool::create_order_success_push($this->goods, $this->result, $this->input);
                return true;
            }

        }
        return false;
    }
}
